<!-- 职级编辑弹窗 -->
<template>
    <el-dialog
      :title="isUpdate?'查看单据明细':'查看单据明细'"
      :visible="visible"
      width="90%"
      :destroy-on-close="true"
      :lock-scroll="false"
      @open="loaddata"
      @update:visible="updateVisible">

      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        height="calc(100vh - 415px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar" v-if="false">
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit(null)"
            >NC回写
          </el-button>
          <el-button
            size="small"
            type="danger"
            icon="el-icon-delete"
            class="ele-btn-icon"
            @click="removeBatch"
            v-if="false"
            >删除
          </el-button>
        </template>
      </ele-pro-table>

      <div slot="footer">
        <el-button @click="updateVisible(false)">关闭</el-button>
        <el-button v-if="false"
          type="primary"
          @click="save"
          >保存
        </el-button>
      </div>
    </el-dialog>
  </template>

  <script>
  export default {
    name: 'XSTHBillDetail',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      dataItem: Object
    },
    data() {
      return {
        // 表单数据
        //form: Object.assign({status: 1}, this.dataItem),
        url: '/c37infrkscbillnew/index',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: "left"
        },
        {
          prop: 'danjNo',
          label: '订单编号',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center'
        },
        {
          prop: 'rukNo',
          label: '入库单号',
          showOverflowTooltip: true,
          minWidth: 140,
          align: 'center'
        },
        {
          prop: 'riqiChar',
          label: '开票日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'danwNo',
          label: '单位编号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'caigouStaff',
          label: '业务员',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'caozStaff',
          label: '操作员',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'hanghao',
          label: '行号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'shangpNo',
          label: '商品编号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'num',
          label: '数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'lot',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center'
        },
        {
          prop: 'shengcChar',
          label: '生产日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'youxChar',
          label: '有效期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'yansRlt',
          label: '验收状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'price',
          label: '价格',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'amout',
          label: '总金额',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'tuihReason',
          label: '退回原因',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'zt',
          label: '下传状态',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'khZzbm',
          label: 'NC组织编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
      ],
      // 表格搜索条件
      where: {rukNo:this.dataItem?this.dataItem.rukNo:''},

        // 表单验证规则
        rules: {
          name: [
            {required: true, message: '请输入职级名称', trigger: 'blur'}
          ],
          status: [
            {required: true, message: '请选择职级状态', trigger: 'blur'}
          ],
          sort: [
            {required: true, message: '请输入排序号', trigger: 'blur'}
          ]
        },
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false
      };
    },
    watch: {
      data() {
        if (this.dataItem) {
          this.form = Object.assign({}, this.dataItem);
          this.isUpdate = true;
        } else {
          this.form = {};
          this.isUpdate = false;
        }
      }
    },
    methods: {
      loaddata(){
        if (this.dataItem) {
          this.where.rukNo = this.dataItem.chukNo?this.dataItem.chukNo:this.dataItem.rukNo;
          if(this.dataItem.chukNo)
          {
            this.where.yewType = this.dataItem.yewType;
          }
          else
          {
            this.where.rukType = this.dataItem.rukType;
          }
          this.$refs.table.reload();
        }
      },
      /* 保存编辑 */
      save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.loading = true;
            this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/level/edit' : '/level/add', this.form).then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit('done');
              } else {
                this.$message.error(res.data.msg);
              }
            }).catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
          } else {
            return false;
          }
        });
      },
      /* 更新visible */
      updateVisible(value) {
        this.$emit('update:visible', value);
      }
    }
  }
  </script>

  <style scoped>
  </style>
